
import { API_BASE_URL, getToken } from "../../utils";
import { request } from "../../utils/request";

export const authGetInforByToken = async (token: string): Promise<{ openid: string; } | '401' | 'error'> => {

    let response = await request({
        url: `${API_BASE_URL}/auth/get_infor_by_token`,
        headers: {
            'Authorization': token
        }
    });
    if (response && response.status === 200) {
        let data = await response.json();
        console.log(data);
        return data;
    } else if (response && response.status === 401) {
        return '401';
    } else {
        return 'error';
    }
}

export const authGetUserInfor = async (): Promise<{ nickname: string; avatar: string } | '401' | 'error'> => {

    let token = getToken();

    let response = await request({
        url: `${API_BASE_URL}/user/userinfor`,
        headers: {
            'Authorization': token
        }
    });

    console.log(response);
    if (response && response.status === 200) {
        let data = await response.json();
        return data;
    } else if (response && response.status === 401) {
        return '401';
    } else {
        return 'error';
    }
}



export const tmpUuidGet = async (uid: string): Promise<any> => {

    let response = await request({
        url: `${API_BASE_URL}/tmpuuid/get/${uid}`,
        headers: {
        }
    });

    console.log(response);
    if (response && response.status === 200) {
        let data = await response.json();
        return data;
    } else if (response && response.status === 401) {
        return '401';
    } else {
        return 'error';
    }
}
